#!/usr/bin/python3
import sys

try:
    t = int(input())
    if t < 1 or t > 100000:
        sys.exit(0)
    for i in range(t):
        n = int(input())
        if n < 10:
            print(n)
            continue
        ret = []
        s = 9
        ans = 1
        while n > s * 2:
            n -= s * 2
            s *= 10
            ans *= 10
        if n % s == 0:
            ans += s - 1
        else:
            ans += n % s - 1
        ret.append(str(ans))
        if n - s <= 0:
            ans = int(ans / 10)
        while ans != 0:
            ret.append(str(ans % 10))
            ans = int(ans / 10)
        print(''.join(ret))

except ValueError:
    pass
except EOFError:
    pass
except MemoryError:
    pass
